package com.snail.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.snail.model.pojo.BizUserQuestionCollect;
import com.snail.response.BaseResponse;
import com.snail.response.ResultUtils;
import com.snail.service.BizUserQuestionCollectService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ysc
 * @descrpiton 用户创建收藏夹
 * @date 2025/7/22 19:30
 **/
@RestController
@RequestMapping("/collect")
public class BizQuestionUserCollectionController {
    @Autowired
    private BizUserQuestionCollectService collectService;

    /**
     * 添加收藏夹
     */
    @PostMapping("/add/{name}")
    public BaseResponse<?> addCollectFolder(@PathVariable String name) {
        boolean saved = collectService.addCollectFolder(name);
        return saved ? ResultUtils.success("添加成功") : ResultUtils.error("添加失败");
    }

    /**
     * 获取当前用户所有收藏夹
     */
    @Operation(summary = "获取用户收藏夹")
    @GetMapping("/list")
    public BaseResponse<?> listByUserId() {
        int userId= StpUtil.getLoginIdAsInt();
        List<BizUserQuestionCollect> list = collectService.getCollectFoldersByUserId(userId);
        return ResultUtils.success(list);
    }

    /**
     * 删除收藏夹
     */
    @DeleteMapping("/delete/{id}")
    public BaseResponse<?> deleteFolder(@PathVariable Integer id) {
        boolean removed = collectService.removeById(id);
        return removed ? ResultUtils.success("删除成功") : ResultUtils.error("删除失败");
    }
}
